package wifiunion.com.notice.fragment;

import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;



import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import wifiunion.com.notice.BaseFragment;
import wifiunion.com.notice.BasePresenter;
import wifiunion.com.notice.Constants;
import wifiunion.com.notice.DateTimePickDialogUtil;
import wifiunion.com.notice.NoticeContact;
import wifiunion.com.notice.R;
import wifiunion.com.notice.entity.NoticeInfoList;
import wifiunion.com.notice.presenter.AddNoticeSBSDPresenter;
import wifiunion.com.notice.presenter.GetNoticeDetailPresenter;
import wifiunion.com.notice.utils.SharedPreferencesUtils;
import wifiunion.com.notice.utils.TimeUtil;
import wifiunion.com.notice.widget.MyDateTimePickerDialog;

/**
 * Created by Administrator on 2016/11/28.
 * 添加识别时段
 */

public class AddRecognitionIntervalFragment extends BaseFragment implements View.OnClickListener, NoticeContact.View {

    private View mMainView;
    private int pageType;
    private String noticeUuid;
    private RadioGroup optRG;
    private RadioButton unlimitedRB;
    private RadioButton customRB;

    private int isdate;

    private String startDate = "2013-9-3";
    private String endDate = "2013-9-11";
    private String startTime;
    private String endTime;
    private String cycle;

    private TextView zhouyiTv;
    private boolean isZhouyiSelect;
    private TextView zhouerTv;
    private boolean isZhouerSelect;
    private TextView zhousanTv;
    private boolean isZhousanSelect;

    private TextView zhousiTv;
    private boolean isZhousiSelect;
    private TextView zhouwuTv;
    private boolean isZhouwuSelect;
    private TextView zhouliuTv;
    private boolean isZhouliuSelect;
    private TextView zhouriTv;
    private boolean isZhouriSelect;
    private TextView startdateTv;
    private TextView enddateTv;

    private MyDateTimePickerDialog mDateTimePickerDialog;

    private TextView stimeTv;
    private TextView etimeTv;

    private AddNoticeSBSDPresenter mAddNoticeSBSDPresenter;
    private GetNoticeDetailPresenter mGetNoticeDetailPresenter;

    private TextView headDowntv;
    private TextView headUpTv;
    private ArrayList<String> cycleList = new ArrayList<String>();
    private ImageView ovalsbsdIv;
    private TextView titlesbsdTv;
    private NoticeInfoList mNoticeInfoList;

    private TimePickerDialog timePickerDialog;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mMainView = inflater.inflate(R.layout.fragment_addrecognitioninterval, container, false);

        mAddNoticeSBSDPresenter = new AddNoticeSBSDPresenter(getContext(), this);
        mGetNoticeDetailPresenter = new GetNoticeDetailPresenter(getContext(), this);
        Bundle bundle = getArguments();
        if (null != bundle) {
            pageType = bundle.getInt("pageType");
            noticeUuid = bundle.getString("noticeUuid");
            if (pageType == 1 || pageType == 2) {
                //查看或者编辑
                mNoticeInfoList = (NoticeInfoList) bundle.getSerializable("notice");
                noticeUuid = mNoticeInfoList.getUuid();
            } else {

            }
        }
        initview();
        setListener();
        return mMainView;
    }

    public void getNoticeDetails(String noticeUuid) {

        String authtoken = SharedPreferencesUtils.getSharedPreferences(
                Constants.CONFIG_AUTHTOKEN, getContext());
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("Authorization", authtoken);
        params.put("uuid", noticeUuid);

        mGetNoticeDetailPresenter.getNoticeDetail(params);

    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    @Override
    public void onResume() {
        super.onResume();
        getView().setFocusableInTouchMode(true);
        getView().requestFocus();
        getView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
//                    getFragmentManager().popBackStack();
                    getActivity().getSupportFragmentManager().popBackStack();
                    return true;
                }
                return false;
            }
        });
    }

    public void initview() {
        ovalsbsdIv = (ImageView) mMainView.findViewById(R.id.oval_sbsd_iv);
        ovalsbsdIv.setBackgroundResource(R.drawable.notice_mark_material_select);
        titlesbsdTv = (TextView) mMainView.findViewById(R.id.title_sbsd_tv);

        headDowntv = (TextView) mMainView.findViewById(R.id.notice_head_down_tv);
        headDowntv.setOnClickListener(this);
        headUpTv = (TextView) mMainView.findViewById(R.id.notice_head_up_tv);
        headUpTv.setOnClickListener(this);
        optRG = (RadioGroup) mMainView.findViewById(R.id.opt_rg);
        unlimitedRB = (RadioButton) mMainView.findViewById(R.id.unlimited);
        customRB = (RadioButton) mMainView.findViewById(R.id.custom);
        unlimitedRB.setChecked(true);

        zhouyiTv = (TextView) mMainView.findViewById(R.id.tv_zhouyi);
        zhouyiTv.setOnClickListener(this);
        zhouerTv = (TextView) mMainView.findViewById(R.id.tv_zhouer);
        zhouerTv.setOnClickListener(this);
        zhousanTv = (TextView) mMainView.findViewById(R.id.tv_zhousan);
        zhousanTv.setOnClickListener(this);
        zhousiTv = (TextView) mMainView.findViewById(R.id.tv_zhousi);
        zhousiTv.setOnClickListener(this);
        zhouwuTv = (TextView) mMainView.findViewById(R.id.tv_zhouwu);
        zhouwuTv.setOnClickListener(this);
        zhouliuTv = (TextView) mMainView.findViewById(R.id.tv_zhouliu);
        zhouliuTv.setOnClickListener(this);
        zhouriTv = (TextView) mMainView.findViewById(R.id.tv_zhouri);
        zhouriTv.setOnClickListener(this);
        startdateTv = (TextView) mMainView.findViewById(R.id.startdate_tv);
        startdateTv.setOnClickListener(this);
        enddateTv = (TextView) mMainView.findViewById(R.id.enddate_tv);
        enddateTv.setOnClickListener(this);

        stimeTv = (TextView) mMainView.findViewById(R.id.tv_stime);
        etimeTv = (TextView) mMainView.findViewById(R.id.tv_etime);
        stimeTv.setOnClickListener(this);
        etimeTv.setOnClickListener(this);

        if (pageType == 0) {
            //初始化回来也要获取一下是否设置过，设置过直接填入
            //获取当前通知详情
            if (null != cycleList && cycleList.size() > 0) {

            } else {
                isZhouyiSelect = true;
                zhouyiTv.setBackgroundResource(R.drawable.rec_button_sel);
                isZhouerSelect = true;
                zhouerTv.setBackgroundResource(R.drawable.rec_button_sel);

                isZhousanSelect = true;
                zhousanTv.setBackgroundResource(R.drawable.rec_button_sel);

                isZhousiSelect = true;
                zhousiTv.setBackgroundResource(R.drawable.rec_button_sel);

                isZhouwuSelect = true;
                zhouwuTv.setBackgroundResource(R.drawable.rec_button_sel);

                isZhouliuSelect = true;
                zhouliuTv.setBackgroundResource(R.drawable.rec_button_sel);

                isZhouriSelect = true;
                zhouriTv.setBackgroundResource(R.drawable.rec_button_sel);

            }

            getNoticeDetails(noticeUuid);

        } else if (pageType == 1) {
            // 查看模式
            optRG.setEnabled(false);
            unlimitedRB.setEnabled(false);
            customRB.setEnabled(false);
            if (mNoticeInfoList.getIsdate() == 0) {
                unlimitedRB.setChecked(true);
            } else {
                customRB.setChecked(true);
            }

            zhouyiTv.setEnabled(false);
            zhouerTv.setEnabled(false);
            zhousanTv.setEnabled(false);
            zhousiTv.setEnabled(false);
            zhouwuTv.setEnabled(false);
            zhouliuTv.setEnabled(false);
            zhouriTv.setEnabled(false);
            if (null != mNoticeInfoList.getCycle()) {

                if (mNoticeInfoList.getCycle().contains("1")) {
                    zhouyiTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("2")) {
                    zhouerTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("3")) {
                    zhousanTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("4")) {
                    zhousiTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("5")) {
                    zhouwuTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("6")) {
                    zhouliuTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
                if (mNoticeInfoList.getCycle().contains("7")) {
                    zhouriTv.setBackgroundResource(R.drawable.rec_button_sel);
                }
            }

            startdateTv.setEnabled(false);
            enddateTv.setEnabled(false);
            if (null != mNoticeInfoList.getStartDate() && mNoticeInfoList.getStartDate().length() > 0) {

                if(mNoticeInfoList.getStartDate().length() == 10)
                {
                    startdateTv.setText(mNoticeInfoList.getStartDate() +" 00:00:00");
                }else
                {
                    startdateTv.setText(mNoticeInfoList.getStartDate());
                }
//                startdateTv.setText(mNoticeInfoList.getStartDate());
            }
            if (null != mNoticeInfoList.getEndDate() && mNoticeInfoList.getEndDate().length() > 0) {

                if(mNoticeInfoList.getEndDate().length() == 10)
                {
                    enddateTv.setText(mNoticeInfoList.getEndDate() +" 23:59:59");
                }else
                {
                    enddateTv.setText(mNoticeInfoList.getEndDate());
                }
//                enddateTv.setText(mNoticeInfoList.getEndDate());
            }

            stimeTv.setEnabled(false);
            etimeTv.setEnabled(false);
            if (null != mNoticeInfoList.getStartTime() && mNoticeInfoList.getStartTime().length() > 0) {
                stimeTv.setText(mNoticeInfoList.getStartTime().substring(0, mNoticeInfoList.getStartTime().length() - 3));
            } else {

            }
            if (null != mNoticeInfoList.getEndTime() && mNoticeInfoList.getEndTime().length() > 0) {
                etimeTv.setText(mNoticeInfoList.getEndTime().substring(0, mNoticeInfoList.getEndTime().length() - 3));
            } else {

            }


        } else if (pageType == 2) {

            getNoticeDetails(noticeUuid);


//            // 编辑模式
//            optRG.setEnabled(true);
//            unlimitedRB.setEnabled(true);
//            customRB.setEnabled(true);
//            if(mNoticeInfoList.getIsdate() == 0)
//            {
//                unlimitedRB.setChecked(true);
//                isdate = 0;
//            }
//            else
//            {
//                customRB.setChecked(true);
//                isdate = 1;
//            }
//
//            zhouyiTv.setEnabled(true);
//            zhouerTv.setEnabled(true);
//            zhousanTv.setEnabled(true);
//            zhousiTv.setEnabled(true);
//            zhouwuTv.setEnabled(true);
//            zhouliuTv.setEnabled(true);
//            zhouriTv.setEnabled(true);
//            if(null != mNoticeInfoList.getCycle())
//            {
//
//                if(mNoticeInfoList.getCycle().contains("1"))
//                {
//                    zhouyiTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhouyiSelect = true;
//                }
//                else
//                {
//                    zhouyiTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhouyiSelect = false;
//                }
//
//                if(mNoticeInfoList.getCycle().contains("2"))
//                {
//                    zhouerTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhouerSelect = true;
//                }
//                else
//                {
//                    zhouerTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhouerSelect = false;
//
//                }
//                if(mNoticeInfoList.getCycle().contains("3"))
//                {
//                    zhousanTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhousanSelect = true;
//                }
//                else
//                {
//                    zhousanTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhousanSelect = false;
//
//                }
//                if(mNoticeInfoList.getCycle().contains("4"))
//                {
//                    zhousiTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhousiSelect = true;
//                }
//                else
//                {
//                    zhousiTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhousiSelect = false;
//
//                }
//                if(mNoticeInfoList.getCycle().contains("5"))
//                {
//                    zhouwuTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhouwuSelect = true;
//                }
//                else
//                {
//                    zhouwuTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhouwuSelect = false;
//                }
//                if(mNoticeInfoList.getCycle().contains("6"))
//                {
//                    zhouliuTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhouliuSelect = true;
//                }
//                else
//                {
//                    zhouliuTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhouliuSelect = false;
//                }
//                if(mNoticeInfoList.getCycle().contains("7"))
//                {
//                    zhouriTv.setBackgroundResource(R.drawable.rec_button_sel);
//                    isZhouriSelect = true;
//                }
//                else
//                {
//                    zhouriTv.setBackgroundResource(R.drawable.rec_button_del);
//                    isZhouriSelect = false;
//                }
//            }
//
//            if(null !=mNoticeInfoList.getStartDate() && mNoticeInfoList.getStartDate().length() >0)
//            {
//                startdateTv.setText(mNoticeInfoList.getStartDate());
//            }
//            if(null !=mNoticeInfoList.getEndDate() && mNoticeInfoList.getEndDate().length() > 0)
//            {
//                enddateTv.setText(mNoticeInfoList.getEndDate());
//            }
//
//
//            if(null !=mNoticeInfoList.getStartTime() && mNoticeInfoList.getStartTime().length() >0)
//            {
//                stimeTv.setText(mNoticeInfoList.getStartTime().substring(0,mNoticeInfoList.getStartTime().length() - 3));
//            }
//            else
//            {
//
//            }
//            if(null !=mNoticeInfoList.getEndTime() && mNoticeInfoList.getEndTime().length() > 0)
//            {
//                etimeTv.setText(mNoticeInfoList.getEndTime().substring(0,mNoticeInfoList.getEndTime().length() - 3));
//            }
//            else
//            {
//
//            }


        }


    }

    public void setListener() {
        optRG.setOnCheckedChangeListener(mylistener);
    }

    public void initData() {

    }

    @Override
    public void onClick(View view) {
        int i = view.getId();
        if (i == R.id.tv_zhouyi) {
            if (isZhouyiSelect) {
                isZhouyiSelect = false;
                zhouyiTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhouyiSelect = true;
                zhouyiTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhouer) {
            if (isZhouerSelect) {
                isZhouerSelect = false;
                zhouerTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhouerSelect = true;
                zhouerTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhousan) {
            if (isZhousanSelect) {
                isZhousanSelect = false;
                zhousanTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhousanSelect = true;
                zhousanTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhousi) {
            if (isZhousiSelect) {
                isZhousiSelect = false;
                zhousiTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhousiSelect = true;
                zhousiTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhouwu) {
            if (isZhouwuSelect) {
                isZhouwuSelect = false;
                zhouwuTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhouwuSelect = true;
                zhouwuTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhouliu) {
            if (isZhouliuSelect) {
                isZhouliuSelect = false;
                zhouliuTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhouliuSelect = true;
                zhouliuTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.tv_zhouri) {
            if (isZhouriSelect) {
                isZhouriSelect = false;
                zhouriTv.setBackgroundResource(R.drawable.rec_button_del);
            } else {
                isZhouriSelect = true;
                zhouriTv.setBackgroundResource(R.drawable.rec_button_sel);

            }


        } else if (i == R.id.startdate_tv) {

            DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
                    getActivity(), startdateTv.getText().toString());
            dateTimePicKDialog.dateTimePicKDialog(startdateTv);

//            String mStartDate = TextUtils.isEmpty(startdateTv.getText().toString()) ? "" : startdateTv.getText().toString();
//            DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
//                    getActivity(), mStartDate, 1);
//            dateTimePicKDialog.dateTimePicKDialog(startdateTv);


        } else if (i == R.id.enddate_tv) {


            DateTimePickDialogUtil dateTimePicKDialog2 = new DateTimePickDialogUtil(
                    getActivity(), enddateTv.getText().toString());
            dateTimePicKDialog2.dateTimePicKDialog(enddateTv);

//            String mEndDate = TextUtils.isEmpty(enddateTv.getText().toString()) ? "" : enddateTv.getText().toString();
//            DateTimePickDialogUtil dateTimePicKDialog1 = new DateTimePickDialogUtil(
//                    getActivity(), mEndDate, 1);
//            dateTimePicKDialog1.dateTimePicKDialog(enddateTv);


        } else if (i == R.id.notice_head_up_tv) {
            getActivity().getSupportFragmentManager().popBackStack();


        } else if (i == R.id.notice_head_down_tv) {
            if (pageType == 0 || pageType == 2) {
                addNoticeSBSD();
            } else if (pageType == 1) {

                AddRecognitionDeviceFragment aif = new AddRecognitionDeviceFragment();
                Bundle bundle = new Bundle();
                bundle.putSerializable("notice", mNoticeInfoList);
                bundle.putInt("pageType", pageType);
                aif.setArguments(bundle);
                //跳转到添加设备页面
                getFragmentManager().beginTransaction().replace(R.id.reight_fl, aif, "44").addToBackStack(null).commit();


            }


        } else if (i == R.id.tv_stime) {
            int hour = 0;
            int minute = 0;

            String time = stimeTv.getText().toString();
            String[] timeArray = time.split(":");
            String hh = timeArray[0];
            String mm = timeArray[1];
            if (Integer.parseInt(hh) < 10) {
                hour = Integer.parseInt(hh.substring(1, 2));
            }
            if (Integer.parseInt(mm) < 10) {
                minute = Integer.parseInt(mm.substring(1, 2));
            }
            timePickerDialog = new TimePickerDialog(
                    getContext(), startTimeSetting, hour,
                    minute, true);
            timePickerDialog.show();


        } else if (i == R.id.tv_etime) {
            int ehour = 0;
            int eminute = 0;

            String etime = etimeTv.getText().toString();
            String[] etimeArray = etime.split(":");
            String ehh = etimeArray[0];
            String emm = etimeArray[1];
            if (Integer.parseInt(ehh) < 10) {
                ehour = Integer.parseInt(ehh.substring(1, 2));
            }
            if (Integer.parseInt(emm) < 10) {
                eminute = Integer.parseInt(emm.substring(1, 2));
            }
            timePickerDialog = new TimePickerDialog(
                    getContext(), endTimeSetting, ehour,
                    eminute, true);
            timePickerDialog.show();


        }


    }

    TimePickerDialog.OnTimeSetListener startTimeSetting = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hour, int minute) {
            String hourStr = "";
            String minuteStr = "";
            if (String.valueOf(hour).length() == 1) {
                hourStr = "0" + hour;
            } else {
                hourStr = String.valueOf(hour);
            }

            if (String.valueOf(minute).length() == 1) {
                minuteStr = "0" + minute;
            } else {
                minuteStr = String.valueOf(minute);
            }

//            SimpleDateFormat format2 = new SimpleDateFormat("yyMMdd");
//            String str = format2.format(new Date(System.currentTimeMillis()));
//            mRealStartTime = str + hourStr + minute + "00";
            stimeTv.setText(hourStr + ":" + minuteStr);
        }
    };


    TimePickerDialog.OnTimeSetListener endTimeSetting = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hour, int minute) {
            String hourStr = "";
            String minuteStr = "";
            if (String.valueOf(hour).length() == 1) {
                hourStr = "0" + hour;
            } else {
                hourStr = String.valueOf(hour);
            }

            if (String.valueOf(minute).length() == 1) {
                minuteStr = "0" + minute;
            } else {
                minuteStr = String.valueOf(minute);
            }

//            SimpleDateFormat format2 = new SimpleDateFormat("yyMMdd");
//            String str = format2.format(new Date(System.currentTimeMillis()));
//            mRealStartTime = str + hourStr + minute + "00";
            etimeTv.setText(hourStr + ":" + minuteStr);
        }
    };


    public void addNoticeSBSD() {
        String authtoken = SharedPreferencesUtils.getSharedPreferences(
                Constants.CONFIG_AUTHTOKEN, getContext());
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("Authorization", authtoken);
        if (!TextUtils.isEmpty(noticeUuid)) {
            params.put("uuid", noticeUuid);
        }
        params.put("isdate", isdate);
        if (isdate != 0) {
            if (checkTime()) {
                params.put("startDate", startdateTv.getText().toString());
                params.put("endDate", enddateTv.getText().toString());
            } else {
                return;
            }
        }
        params.put("startTime", stimeTv.getText().toString() + ":00");
        params.put("endTime", etimeTv.getText().toString() + ":00");
        getCycleList();

        if (null != cycleList && cycleList.size() >= 1) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < cycleList.size(); i++) {
                sb.append(cycleList.get(i));
                if (i < cycleList.size() - 1) {
                    sb.append(",");
                }

            }
            params.put("cycle", sb.toString());
            mAddNoticeSBSDPresenter.addNoticeSBSD(params);
        } else {
            Toast.makeText(getContext(), "请选择周天", Toast.LENGTH_SHORT).show();
        }


    }

    public void getCycleList() {
        cycleList.clear();
        if (isZhouyiSelect) {
            cycleList.add("1");
        }
        if (isZhouerSelect) {
            cycleList.add("2");
        }
        if (isZhousanSelect) {
            cycleList.add("3");
        }
        if (isZhousiSelect) {
            cycleList.add("4");
        }
        if (isZhouwuSelect) {
            cycleList.add("5");
        }
        if (isZhouliuSelect) {
            cycleList.add("6");
        }
        if (isZhouriSelect) {
            cycleList.add("7");
        }
    }

    private void showDateTimePicker(Date defaultDate, TextView inputET) {
        if (mDateTimePickerDialog == null) {
            mDateTimePickerDialog = new MyDateTimePickerDialog(getContext());
            mDateTimePickerDialog.setOkBtnListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    TextView editText = (TextView) v.getTag();
                    editText.setText(mDateTimePickerDialog.getYMDDateTimeString());
                    mDateTimePickerDialog.cancel();
                }
            });
        }

        mDateTimePickerDialog.setDefaultDateTime(defaultDate);
        mDateTimePickerDialog.setOkBtnTag(inputET);
        mDateTimePickerDialog.show();
    }


    private boolean checkTime() {
        if (!TextUtils.isEmpty(startdateTv.getText()) && !TextUtils.isEmpty(enddateTv.getText())) {
            long startTimeMillSeconds = TimeUtil.getYMDCommonTime(startdateTv.getText().toString());
            long endTimeMillSeconds = TimeUtil.getYMDCommonTime(enddateTv.getText().toString());
            if (startTimeMillSeconds > 0 && endTimeMillSeconds > 0) {
                if (startTimeMillSeconds >= endTimeMillSeconds) {
                    Toast.makeText(getContext(), "开始时间必须小于结束时间", Toast.LENGTH_SHORT).show();
                    return false;
                }
                return true;
            }

        }
        Toast.makeText(getContext(), "请输入正确的时间格式", Toast.LENGTH_SHORT).show();
        return false;
    }


    RadioGroup.OnCheckedChangeListener mylistener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup Group, int checkedId) {

            if (checkedId == unlimitedRB.getId()) {

                isdate = 0;
            } else if (checkedId == customRB.getId()) {
                isdate = 1;
            } else {
                isdate = 0;
            }


        }
    };


    @Override
    public void onProgress() {

    }

    @Override
    public void onError(Object obj) {

    }

    @Override
    public void onSuccess(Object obj) {

    }

    @Override
    public void getGroupListSuccess(Object obj) {

    }

    @Override
    public void getNoticeListSuccess(Object obj) {

    }

    @Override
    public void getNotificationUserSuccess(Object obj) {

    }

    @Override
    public void getNotificationRelGroupList(Object obj) {

    }

    @Override
    public void getNoticeRelGroupMemberListSuccess(Object obj) {

    }

    @Override
    public void addNoticeSBDXSuccess(String noticeUuid) {


    }

    @Override
    public void addSBSDSuccess(Object obj) {

        if (pageType == 0) {
            AddRecognitionDeviceFragment aif = new AddRecognitionDeviceFragment();
            Bundle bundle = new Bundle();
            bundle.putString("noticeUuid", noticeUuid);
            bundle.putInt("pageType", pageType);
            aif.setArguments(bundle);

            //跳转到添加设备页面
            getFragmentManager().beginTransaction().replace(R.id.reight_fl, aif, "44").addToBackStack(null).commit();
        } else {
            AddRecognitionDeviceFragment aif = new AddRecognitionDeviceFragment();
            Bundle bundle = new Bundle();
            bundle.putSerializable("notice", mNoticeInfoList);
            bundle.putInt("pageType", pageType);
            aif.setArguments(bundle);
            //跳转到添加设备页面
            getFragmentManager().beginTransaction().replace(R.id.reight_fl, aif, "44").addToBackStack(null).commit();


        }


    }

    @Override
    public void onGetDeviceLocListSuccess(Object obj) {


    }

    @Override
    public void onGetDeviceListSuccess(Object obj) {

    }

    @Override
    public void onGetNoticeDeviceGroupListSuccess(Object obj) {

    }

    @Override
    public void onGetNoticeDeviceGroupUuidSuccess(Object obj) {

    }

    @Override
    public void addNoticeDeviceSuccess(Object obj) {

    }

    @Override
    public void getTopGroupListSuccess(Object obj) {

    }

    @Override
    public void getNoticeTargetListSuccess(Object obj) {

    }

    @Override
    public void onGetNoticeTargetRelGroupListSuccess(Object obj) {

    }

    @Override
    public void onGetNoticeTargetGroupUuidSuccess(Object obj) {

    }

    @Override
    public void addNoticeTarGetDeviceSuccess(Object obj) {

    }

    @Override
    public void addNoticeDataSuccess(Object obj) {

    }

    @Override
    public void deleteNoticeSuccess(Object obj) {

    }

    @Override
    public void addNoticeGroupSuccess(Object obj) {

    }

    @Override
    public void addNoticeRelGroupSuccess(Object obj) {

    }

    @Override
    public void setNoticeFromSuccess(Object obj) {

    }

    @Override
    public void getNoticeDetailSuccess(final Object obj) {
        //获取到通知详情

        if (null != getActivity()) {


            NoticeInfoList mNoticeInfoList = (NoticeInfoList) obj;
            if (null != mNoticeInfoList) {

                if (mNoticeInfoList.getIsdate() == 0) {
                    unlimitedRB.setChecked(true);
                } else {
                    customRB.setChecked(true);
                }

                if (null != mNoticeInfoList.getCycle()) {

                    if (mNoticeInfoList.getCycle().contains("1")) {
                        zhouyiTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhouyiSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("2")) {
                        zhouerTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhouerSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("3")) {
                        zhousanTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhousanSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("4")) {
                        zhousiTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhousiSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("5")) {
                        zhouwuTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhouwuSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("6")) {
                        zhouliuTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhouliuSelect = true;
                    }
                    if (mNoticeInfoList.getCycle().contains("7")) {
                        zhouriTv.setBackgroundResource(R.drawable.rec_button_sel);
                        isZhouriSelect = true;
                    }
                }

                if (null != mNoticeInfoList.getStartDate() && mNoticeInfoList.getStartDate().length() > 0) {

                    if(mNoticeInfoList.getStartDate().length() == 10)
                    {
                        startdateTv.setText(mNoticeInfoList.getStartDate() +" 00:00:00");
                    }else
                    {
                        startdateTv.setText(mNoticeInfoList.getStartDate());
                    }

                } else {
                    startdateTv.setText(TimeUtil.getCurYMDTime());
                }
                if (null != mNoticeInfoList.getEndDate() && mNoticeInfoList.getEndDate().length() > 0) {
                    if(mNoticeInfoList.getEndDate().length() == 10)
                    {
                        enddateTv.setText(mNoticeInfoList.getEndDate() +" 23:59:59");
                    }else
                    {
                        enddateTv.setText(mNoticeInfoList.getEndDate());
                    }
//                    enddateTv.setText(mNoticeInfoList.getEndDate());
                } else {
                    enddateTv.setText(TimeUtil.getCurYMDTime());
                }

                if (null != mNoticeInfoList.getStartTime() && mNoticeInfoList.getStartTime().length() > 0) {
                    stimeTv.setText(mNoticeInfoList.getStartTime().substring(0, mNoticeInfoList.getStartTime().length() - 3));
                } else {
                    stimeTv.setText("00:00");
                }
                if (null != mNoticeInfoList.getEndTime() && mNoticeInfoList.getEndTime().length() > 0) {
                    etimeTv.setText(mNoticeInfoList.getEndTime().substring(0, mNoticeInfoList.getEndTime().length() - 3));
                } else {
                    etimeTv.setText("23:59");
                }


            }

        }


    }

    @Override
    public void deleteNoticeGroupSuccess(Object obj) {

    }

    @Override
    public void setPresenter(BasePresenter tp) {

    }
}
